import groovy.io.FileType

class Example{
    static void main(String[] args){
        def curDir = new File(System.getProperty("user.dir"));
        def fileName = curDir.getAbsolutePath() + "/demo.txt";
        def file = new File(fileName);
        // file.mkdir(); // 创建目录
        // file.delete(); // 删除文件
        println("curDir is directory:"+curDir.isDirectory());        
        println("$fileName is file:"+curDir.isFile());
        if(file.exists()){            
            println(fileName+" exists");
        }else{
            println(fileName+" not exists");
            file << "this is the demo";
        }

        println("复制文件...");
        def tmp = curDir.getAbsolutePath() + "/tmp";
        def tmpDir = new File(tmp);
        def srcFileName = tmp + "/hello.txt";
        def dstFileName = tmp + "/result.txt";
        if(!tmpDir.exists()){
            tmpDir.mkdir();
        }
        def src = new File(srcFileName);
        def dst = new File(dstFileName);
        dst << src.text;

        println("获取目录内容...");
        def rootFiles = curDir.listRoots();
        println(rootFiles);
        // new File("D:\\Document\\Info\\秒懂手机\\Data").eachFile { file ->
        //     println file.getAbsolutePath()
        // }
        
    //     rootFiles.each { 
    //      file -> println file.absolutePath 
    //   }

        eachDemo();
    }

    static void eachDemo(){
        def a = 1..5;
        println("each...");
        a.each {
            if (it == 2){
                return true; // 满足条件 相当于break
            }
            println(it);
        }

        println("find...");
        a.find {
            if(it >= 2){
                return true;
            }
            println it;
        }
    }
}